import request from '@/axios'
import type { RealmForm, RealmTableView } from './types'

const pathPrefix = '/api/realm'

export const query = (data: PaginationRequest): Promise<PaginationResponse<RealmTableView>> => {
    return request.post({
        url: `${pathPrefix}/query`,
        data
    })
}

export const get = (id: string): Promise<RealmForm> => {
    return request.get({
        url: `${pathPrefix}/${id}`
    })
}

export const add = (data: RealmForm): Promise<ApiResult> => {
    return request.post({
        url: `${pathPrefix}`,
        data
    })
}

export const edit = (id: string, data: RealmForm): Promise<ApiResult> => {
    return request.put({
        url: `${pathPrefix}/${id}`,
        data
    })
}

export const remove = (id: string): Promise<ApiResult> => {
    return request.delete({
        url: `${pathPrefix}/${id}`
    })
}

export const options = (): Promise<OptionItem[]> => {
    return request.get({
        url: `${pathPrefix}/options`
    })
}